import sys

from Ui_Incaui import Ui_MainWindow
from PyQt5.QtWidgets import *
from figure import *
from PyQt5.QtGui import *
 
 
class MyMainWindow(QMainWindow,Ui_MainWindow):
    def __init__(self,parent =None):
        super(MyMainWindow,self).__init__(parent)
        self.setupUi(self)
        # jpg = QPixmap(r'./inca-5/Photos.jpg')
        jpg = QPixmap(r'./Photos.jpg')
        self.label.setPixmap(jpg)
    
    # 打开文件
    def openfile(self):
        # 清空列表
        self.textBrowser.clear()
        # 对话框用于选择文件或目录
        options = QFileDialog.Options()
        mdf_file_path, _ = QFileDialog.getOpenFileName(self, "打开文件", "", "Dat Files (*.dat);;All Files (*)", options=options)
        # 显示文件及其路径
        self.textBrowser.setText(mdf_file_path)
    # 分析节气门开度，进气压力，喷油量数据
    def click1(self):
        mdf_file_path=self.textBrowser.toPlainText()
        a=1
        if mdf_file_path:
            import inca
            l10,l20,l30,l40=inca.inca(mdf_file_path,a)
            for i in range(len(l10)):                
                if i==0:                    
                    self.textEdit.setTextColor(QColor(255,0,0))
                    self.textEdit.append(l10[i])
                    self.textEdit.append('\n')
                if i>0:
                    self.textEdit.setTextColor(QColor(0,0,0))
                    self.textEdit.append(l10[i])
                    self.textEdit.append('\n')
            for i in range(len(l20)):
                if i==0:
                    self.textEdit.setTextColor(QColor(255,0,0))
                    self.textEdit.append(l20[i])
                    self.textEdit.append('\n')
                if i>0:    
                    self.textEdit.setTextColor(QColor(0,0,0))
                    self.textEdit.append(l20[i])
                    self.textEdit.append('\n')
            for i in range(len(l30)):
                if i==0:
                    self.textEdit.setTextColor(QColor(255,0,0))
                    self.textEdit.append(l30[i])
                    self.textEdit.append('\n')
                if i>0:    
                    self.textEdit.setTextColor(QColor(0,0,0))
                    self.textEdit.append(l30[i])
                    self.textEdit.append('\n')
    def click2(self):
        mdf_file_path=self.textBrowser.toPlainText()
        a=1
        if mdf_file_path:
            import inca
            l10,l20,l30,l40=inca.inca(mdf_file_path,a)
            for i in range(len(l10)):
                if i==0:
                    self.textEdit_2.setTextColor(QColor(255,0,0))
                    self.textEdit_2.append(l10[i])
                    self.textEdit_2.append('\n')
                if i>0:    
                    self.textEdit_2.setTextColor(QColor(0,0,0))
                    self.textEdit_2.append(l10[i])
                    self.textEdit_2.append('\n')
            for i in range(len(l20)):
                if i==0:
                    self.textEdit_2.setTextColor(QColor(255,0,0))
                    self.textEdit_2.append(l20[i])
                    self.textEdit_2.append('\n')
                if i>0:    
                    self.textEdit_2.setTextColor(QColor(0,0,0))
                    self.textEdit_2.append(l20[i])
                    self.textEdit_2.append('\n')
            for i in range(len(l30)):
                if i==0:
                    self.textEdit_2.setTextColor(QColor(255,0,0))
                    self.textEdit_2.append(l30[i])
                    self.textEdit_2.append('\n')
                if i>0:    
                    self.textEdit_2.setTextColor(QColor(0,0,0))
                    self.textEdit_2.append(l30[i])
                    self.textEdit_2.append('\n')
    # 分析空燃比数据
    def click3(self):
        mdf_file_path=self.textBrowser.toPlainText()
        a=1
        if mdf_file_path:
            import inca
            l10,l20,l30,l40=inca.inca(mdf_file_path,a)
            for i in range(len(l40)):
                if i==0:
                    self.textEdit.setTextColor(QColor(255,0,0))
                    self.textEdit.append(l40[i])
                    self.textEdit.append('\n')
                if i>0:    
                    self.textEdit.setTextColor(QColor(0,0,0))
                    self.textEdit.append(l40[i])
                    self.textEdit.append('\n')
    def click4(self):
        mdf_file_path=self.textBrowser.toPlainText()
        a=1
        if mdf_file_path:
            import inca
            l10,l20,l30,l40=inca.inca(mdf_file_path,a)
            for i in range(len(l40)):
                if i==0:
                    self.textEdit_2.setTextColor(QColor(255,0,0))
                    self.textEdit_2.append(l40[i])
                    self.textEdit_2.append('\n')
                if i>0:    
                    self.textEdit_2.setTextColor(QColor(0,0,0))
                    self.textEdit_2.append(l40[i])
                    self.textEdit_2.append('\n')
    # 分析缸温，进气温度，电池电压数据
    def click5(self):
        mdf_file_path=self.textBrowser.toPlainText()
        a=2
        if mdf_file_path:
            import inca
            l10,l20,l30=inca.inca(mdf_file_path,a)
            for i in range(len(l10)):                
                if i==0:                    
                    self.textEdit.setTextColor(QColor(255,0,0))
                    self.textEdit.append(l10[i])
                    self.textEdit.append('\n')
                if i>0:
                    self.textEdit.setTextColor(QColor(0,0,0))
                    self.textEdit.append(l10[i])
                    self.textEdit.append('\n')
            for i in range(len(l20)):
                if i==0:
                    self.textEdit.setTextColor(QColor(255,0,0))
                    self.textEdit.append(l20[i])
                    self.textEdit.append('\n')
                if i>0:    
                    self.textEdit.setTextColor(QColor(0,0,0))
                    self.textEdit.append(l20[i])
                    self.textEdit.append('\n')
            for i in range(len(l30)):
                if i==0:
                    self.textEdit.setTextColor(QColor(255,0,0))
                    self.textEdit.append(l30[i])
                    self.textEdit.append('\n')
                if i>0:    
                    self.textEdit.setTextColor(QColor(0,0,0))
                    self.textEdit.append(l30[i])
                    self.textEdit.append('\n')
    def click6(self):
        mdf_file_path=self.textBrowser.toPlainText()
        a=2
        if mdf_file_path:
            import inca
            l10,l20,l30=inca.inca(mdf_file_path,a)
            for i in range(len(l10)):
                if i==0:
                    self.textEdit_2.setTextColor(QColor(255,0,0))
                    self.textEdit_2.append(l10[i])
                    self.textEdit_2.append('\n')
                if i>0:    
                    self.textEdit_2.setTextColor(QColor(0,0,0))
                    self.textEdit_2.append(l10[i])
                    self.textEdit_2.append('\n')
            for i in range(len(l20)):
                if i==0:
                    self.textEdit_2.setTextColor(QColor(255,0,0))
                    self.textEdit_2.append(l20[i])
                    self.textEdit_2.append('\n')
                if i>0:    
                    self.textEdit_2.setTextColor(QColor(0,0,0))
                    self.textEdit_2.append(l20[i])
                    self.textEdit_2.append('\n')
            for i in range(len(l30)):
                if i==0:
                    self.textEdit_2.setTextColor(QColor(255,0,0))
                    self.textEdit_2.append(l30[i])
                    self.textEdit_2.append('\n')
                if i>0:    
                    self.textEdit_2.setTextColor(QColor(0,0,0))
                    self.textEdit_2.append(l30[i])
                    self.textEdit_2.append('\n')
    # 判断全过程正时                    
    def click7(self):
        mdf_file_path=self.textBrowser.toPlainText()
        a=3
        if mdf_file_path:
            import inca
            l10=inca.inca(mdf_file_path,a)
            for i in range(len(l10)):
                if i==0:
                    self.textEdit.setTextColor(QColor(255,0,0))
                    self.textEdit.append(l10[i])
                    self.textEdit.append('\n')
                if i>0:    
                    self.textEdit.setTextColor(QColor(0,0,0))
                    self.textEdit.append(l10[i])
                    self.textEdit.append('\n')
    def click8(self):
        mdf_file_path=self.textBrowser.toPlainText()
        a=3
        if mdf_file_path:
            import inca
            l10=inca.inca(mdf_file_path,a)
            for i in range(len(l10)):
                if i==0:
                    self.textEdit_2.setTextColor(QColor(255,0,0))
                    self.textEdit_2.append(l10[i])
                    self.textEdit_2.append('\n')
                if i>0:    
                    self.textEdit_2.setTextColor(QColor(0,0,0))
                    self.textEdit_2.append(l10[i])
                    self.textEdit_2.append('\n')
    # 关闭
    def close(self):
        # 退出
        quit()
 
if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWin = MyMainWindow()
    myWin.show()
    sys.exit(app.exec_())   